function G(id) {return document.getElementById(id);}
var x,y,x1,y1;var x2,y2,x12,y12;
var map = new BMap.Map("car-pool-city-map");
map.centerAndZoom("苏州",15);                   // 初始化地图,设置城市和地图级别。
var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
    {"input" : "city-map1"
        ,"location" : map
    });
var ac1 = new BMap.Autocomplete(    //建立一个自动完成的对象
{"input" : "city-map2"
    ,"location" : map
});
ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
    var str = "";
    var _value = e.fromitem.value;
    var value = "";
    if (e.fromitem.index > -1) {
        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    }
    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

    value = "";
    if (e.toitem.index > -1) {
        _value = e.toitem.value;
        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    }
    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
    G("city-map3").innerHTML = str;
});


//var myValue;
ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
    var _value = e.item.value;
    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    G("city-map3").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
    search(function(l){
        setPlace(l.getResults().getPoi(0).point);
    })(myValue);
});
ac1.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
    var _value = e.item.value;
    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    G("city-map4").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
    search(function(l){
        setPlace1(l.getResults().getPoi(0).point);
    })(myValue);
});
function search(onSearchComplete){
    var local = new BMap.LocalSearch(map, { //智能搜索
        onSearchComplete: function(){
            onSearchComplete(local);
        }
    });
    return function(keyword){
        local.search(keyword);
    };
}
function setPlace(pp) {
    map.clearOverlays();    //清除地图上所有覆盖物
    map.centerAndZoom(pp, 18);
    x = pp.lng;
    y = pp.lat;
    map.addOverlay(new BMap.Marker(pp));
}
function setPlace1(pp) {
    map.clearOverlays();    //清除地图上所有覆盖物
    map.centerAndZoom(pp, 18);
    x1 = pp.lng;
    y1 = pp.lat;
    map.addOverlay(new BMap.Marker(pp));
}
map.enableScrollWheelZoom();//启用地图滚轮放大缩小
map.enableDoubleClickZoom();//启用鼠标双击放大，默认启用(可不写)
map.enableKeyboard();//启用键盘上下左右键移动地图


var map2 = new BMap.Map("car-pool-search-map");map2.centerAndZoom("苏州",15);// 初始化地图,设置城市和地图级别。
var ac2 = new BMap.Autocomplete(    //建立一个自动完成的对象
    {"input" : "search-map1"
        ,"location" : map2
    });
var ac12 = new BMap.Autocomplete(    //建立一个自动完成的对象
{"input" : "search-map2"
    ,"location" : map2
});
ac2.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
    var str= "";
    var _value = e.fromitem.value;
    var value = "";
    if (e.fromitem.index > -1) {
        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    }
    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

    value= "";
    if (e.toitem.index > -1) {
        _value = e.toitem.value;
        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    }
    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
    G("search-map3").innerHTML = str;
});

//var myValue;
ac2.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
    var _value = e.item.value;
    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    G("search-map3").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

    search(function(l){
        setPlace(l.getResults().getPoi(0).point);
    })(myValue);

});
ac12.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
    var _value = e.item.value;
    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    G("search-map3").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

    search(function(l){
        setPlace1(l.getResults().getPoi(0).point);
    })(myValue);

});

function search2(onSearchComplete){
    var local = new BMap.LocalSearch(map2, { //智能搜索
        onSearchComplete: function(){
            onSearchComplete(local);
        }
    });
    return function(keyword){
        local.search(keyword);
    };
}

function setPlace2(pp) {
    map2.clearOverlays();    //清除地图上所有覆盖物
    map2.centerAndZoom(pp2, 18);
    x2 = pp2.lng;
    y2 = pp2.lat;
    map2.addOverlay(new BMap.Marker(pp));
}
function setPlace12(pp) {
    map2.clearOverlays();    //清除地图上所有覆盖物
    map2.centerAndZoom(pp12, 18);
    x12 = pp12.lng;
    y12 = pp12.lat;
    map2.addOverlay(new BMap.Marker(pp1));
}
map2.enableScrollWheelZoom();//启用地图滚轮放大缩小
map2.enableDoubleClickZoom();//启用鼠标双击放大，默认启用(可不写)
map2.enableKeyboard();//启用键盘上下左右键移动地图